import React, { useEffect, useRef } from 'react'

class CustomTextInput extends React.Component<any, any> {
    textInput: any = React.createRef();
    handleFocus = () => {
        this.textInput.current.focus()
    }
    render() {
        return (
            <div>
                <input
                    type="text"
                    ref={this.textInput} />
            </div>
        );
    }
}

const AutoFocusTextInput = () => {
    const textInput: any = useRef()

    useEffect(() => {
        console.log(textInput, 'textInput')
        textInput.current.handleFocus()
    })

    return (
        <CustomTextInput ref={textInput} />
    );
}

export default AutoFocusTextInput;